package cn.edu.hitwh.yibao.service.impl;

import java.util.List;

import cn.edu.hitwh.yibao.entity.DiagnosisProject;
import cn.edu.hitwh.yibao.mapper.DiagnosisProjectMapper;
import cn.edu.hitwh.yibao.service.DiagnosisProjectService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import cn.edu.hitwh.yibao.form.DiagnosisProjectForm;

@Service
public class DiagnosisProjectServiceImpl implements DiagnosisProjectService {
	@Autowired
	private DiagnosisProjectMapper diagnosisProjectMapper;

	@Override
	public String select(DiagnosisProjectForm diagnosisProjectForm, Model model) {
		DiagnosisProject hos = new DiagnosisProject();
		BeanUtils.copyProperties(diagnosisProjectForm, hos);
		List<DiagnosisProject> list = diagnosisProjectMapper.selectList(hos);
		model.addAttribute("diaList", list);
		return "/diagnosisProject/select";
	}

	@Override
	public String add(DiagnosisProjectForm diagnosisProjectForm, Model model) {
		DiagnosisProject hos = new DiagnosisProject();
		BeanUtils.copyProperties(diagnosisProjectForm, hos);
		int count = diagnosisProjectMapper.insert(hos);
		if (count > 0) {
			return "redirect:/diagnosisProject/addComplete";
		} else {
			model.addAttribute("addResult","添加药品失败！");
			return "/diagnosisProject/select";
		}
	}

	@Override
	public String updateInit(String diaId, Model model) {
		DiagnosisProject hos = diagnosisProjectMapper.selectById(diaId);
		model.addAttribute("hos",hos);
		return "/diagnosisProject/update";
	}
	@Override
	public String update(DiagnosisProjectForm diagnosisProjectForm, Model model) {
		DiagnosisProject hos=new DiagnosisProject();
		BeanUtils.copyProperties(diagnosisProjectForm,hos);
		int count = diagnosisProjectMapper.update(hos);
		if (count > 0) {
			return "redirect:/diagnosisProject/updateComplete";
		} else {
			return "/diagnosisProject/select";
		}
	}
	@Override
	public String delete(String diaId, Model model) {
		int count = diagnosisProjectMapper.delete(diaId);
		if (count > 0) {
			return "redirect:/diagnosisProject/deleteComplete";
		}else {
			model.addAttribute("deleteResult","删除药品失败！");
			return "/diagnosisProject/select";
		}
	}
	@Override
	public String detail(String diaId, Model model) {
		DiagnosisProject hos = diagnosisProjectMapper.selectById(diaId);
		model.addAttribute("hos",hos);
		return "/diagnosisProject/detail";
	}
	
}
